package com.bestcem.xm.txtanls.controller.convert;

import cn.hutool.core.collection.CollUtil;
import com.bestcem.xm.common.core.uitls.DateUtil;
import com.bestcem.xm.txtanls.controller.vo.RecordInfoVO;
import com.bestcem.xm.txtanls.service.dto.record.RecordDetailDTO;
import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * @className
 * @description
 * @author gy.liu
 * @date 2021/8/6 14:42
 * @version 2.0
 **/
public class RecordConvert {

    /**
     * 原话记录转换
     * @version v1.0
     * @param dataList
     * @return List<RecordInfo>
     * @author gy.liu
     * @date 2021/8/6
     */
    public static List<RecordInfoVO> listRecordTransfer(List<RecordDetailDTO> dataList) {
        List<RecordInfoVO> recordInfos = new ArrayList<>(dataList.size());
        for (int i = 0; i < dataList.size(); i++) {
            RecordDetailDTO recordDetailDTO = dataList.get(i);
            RecordInfoVO recordInfo = voToResponse(recordDetailDTO);
            recordInfos.add(recordInfo);
        }
        return recordInfos;
    }

    /**
     * 原话记录转化
     * @version v1.0
     * @param data
     * @return RecordInfoVO
     * @author gy.liu
     * @date 2021/8/10
     */
    public static RecordInfoVO voToResponse(RecordDetailDTO data) {
        RecordInfoVO builder = new RecordInfoVO();
        if (StringUtils.isNotBlank(data.getId())) {
            builder.setId(data.getId());
        }
        if (StringUtils.isNotBlank(data.getContent())) {
            builder.setContent(data.getContent());
        }
        if (StringUtils.isNotBlank(data.getProjectId())) {
            builder.setProjectId(data.getProjectId());
        }
        if (Objects.nonNull(data.getSentimentScore())) {
            builder.setSentimentScore(data.getSentimentScore());
        }
        if (StringUtils.isNotBlank(data.getWorktableId())) {
            builder.setWorktableId(data.getWorktableId());
        }
        if (StringUtils.isNotBlank(data.getWorktableName())) {
            builder.setWorktableName(data.getWorktableName());
        }
        if (StringUtils.isNotBlank(data.getCollectionId())) {
            builder.setCollectionId(data.getCollectionId());
        }
        if (Objects.nonNull(data.getSentiment())) {
            builder.setSentiment(data.getSentiment());
        }
        if (StringUtils.isNotBlank(data.getFieldId())) {
            builder.setFieldId(data.getFieldId());
        }
        if (StringUtils.isNotBlank(data.getFieldName())) {
            builder.setFieldName(data.getFieldName());
        }
        if (Objects.nonNull(data.getTime())) {
            builder.setTime(DateUtil.formatString(data.getTime()));
        }
        if (StringUtils.isNotBlank(data.getIndustryId())) {
            builder.setIndustryId(data.getIndustryId());
        }
        if (StringUtils.isNotBlank(data.getSurveyId())) {
            builder.setSurveyId(data.getSurveyId());
        }
        if (StringUtils.isNotBlank(data.getTopicInfo())) {
            builder.setTopicInfo(data.getTopicInfo());
        }
        if (Objects.nonNull(data.getFlag())) {
            builder.setFlag(data.getFlag());
        }

        if (CollUtil.isNotEmpty(data.getViews())) {
            if (CollUtil.isNotEmpty(data.getViews())) {
                builder.setViews(data.getViews());
            }
        }
        if (Objects.nonNull(data.getCreatedDate())) {
            builder.setCreatedDate(data.getCreatedDate());
        }
        if (StringUtils.isNotBlank(data.getCreatedId())) {
            builder.setCreatedId(data.getCreatedId());
        }
        if (Objects.nonNull(data.getUpdatedDate())) {
            builder.setUpdatedDate(data.getUpdatedDate());
        }
        if (StringUtils.isNotBlank(data.getUpdatedId())) {
            builder.setUpdatedId(data.getUpdatedId());
        }
        return builder;
    }
}
